package de.szut.ita13.rs.wave.controller;

import java.awt.Graphics;
import java.util.ArrayList;
import java.util.LinkedList;

import de.szut.ita13.rs.wave.entity.Entity;

public class Controller {

	public static enum Modification  {
		ADD, REMOVE;
	}
	
	public LinkedList<Entity> entities = new LinkedList<Entity>();
	private ArrayList<Entity> entitiesToRemove = new ArrayList<Entity>();
	private ArrayList<Entity> entitiesToAdd = new ArrayList<Entity>();
	
	public void tick() {
		for(Entity entity : entities)  {
			entity.tick();
		}
		
	}
	
	public void render(Graphics g) {
		for(Entity entity : entities) {
			entity.render(g);
		}
	}
	
	public void addEntity(Entity entity) {
		entities.add(entity);
	}
	
	public void removeEntity(Entity entity) {
		entities.remove(entity);
	}
	
	public void runModificationLists() {
		for(Entity entity : entitiesToAdd) {
			entities.add(entity);
		}
		for(Entity entity : entitiesToRemove) {
			entities.remove(entity);
		}
		entitiesToAdd.clear();
		entitiesToRemove.clear();
	}
	
	public void modificateEntity(Entity entity, Modification mod) {
		switch(mod) {
		case ADD:
			entitiesToAdd.add(entity);
			break;
		case REMOVE:
			entitiesToRemove.add(entity);
			break;
		}
	}
	
}
